package com.example.springboot.controller;

import com.example.springboot.common.Result;
import com.example.springboot.entity.Applications; // Update import
import com.example.springboot.entity.interviews; // Update import
import com.example.springboot.service.InterviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin(origins = "http://localhost:7070")
@RestController
@RequestMapping("/interviews")
public class InterviewController {

    @Autowired
    private InterviewService interviewService;

    @GetMapping("/all")
    public Result getAllInterview() {
        List<interviews> interviewsList = interviewService.getAllInterview();
        return Result.success(interviewsList);
    }

    @GetMapping("/get/{id}")
    public interviews getInterviewById(@PathVariable Long id) {
        return interviewService.getInterviewById(id);
    }

    @PostMapping("/create")
    public interviews createInterview(@RequestBody interviews interview) {
        return interviewService.createInterview(interview);
    }

    @PutMapping("/update")
    public interviews updateInterview(@RequestBody interviews interview) {
        return interviewService.updateInterview(interview);
    }
    @PutMapping("/updateApp")
    public Applications updateAPPInterview(@RequestBody Applications application) {
        System.out.println(application);
        return interviewService.updateAPPInterview(application);
    }

    @DeleteMapping("/delete/{id}")
    public void deleteInterview(@PathVariable Long id) {
        interviewService.deleteInterview(id);
    }

    @DeleteMapping("/batch-delete")
    public Result deleteInventoryBatch(@RequestBody List<Long> ids) {
        try {
            interviewService.batchDeleteInterviews(ids);
            return Result.success("批量删除成功");
        } catch (Exception e) {
            return Result.error("批量删除失败：" + e.getMessage());
        }
    }

    @GetMapping("/search")
    public Result searchInterviews(@RequestParam(required = false) String keyword) {
        try {
            List<interviews> interviewsList = interviewService.searchInterviews(keyword);
            return Result.success(interviewsList);
        } catch (Exception e) {
            return Result.error("搜索面试失败：" + e.getMessage());
        }
    }

    @GetMapping("/InterDataAll")
    public Result getInterDataAll() {
        List<interviews> interviewsList = interviewService.getInterDataAll();
        return Result.success(interviewsList);
    }
}

